<?php
/**********************************************************
  eCode Marketing System
  Version 0.1
  Login Form (/admin/login.php)
**********************************************************/

// Require configuration
define("FROMSCRIPT", true);
require dirname(__FILE__) . "/../config.php";

// Start session if not already started
session_start();

if(isset($_SESSION['login_t'])) {

	/* If we're logged in, take us to the admin menu page and
	ensure the rest of the code isn't run */

	header("Location: /admin/index.php");
	exit;
}

$pagetitle = "Login (Admin)";
$pageheading = "Login to Administer " . SITE_NAME;
$page_content = "<hr />\n";
$page_content .= "<p>Please log in using your credentials for the " . SITE_NAME . ".<br />\n";
$page_content .= "If you need assistance, please contact your administrator.</p>\n";

if(isset($_SESSION['error'])) {
	$page_content .= "<div id=\"error-box\">\n";
	$page_content .= $_SESSION['error'] . "\n";
	$page_content .= "</div>\n";
}

$page_content .= "<form action=\"/admin/handler.login.php\" method=\"post\">";
$page_content .= "<table id=\"login-box\">\n";
$page_content .= "<tr><td class=\"rightalign\"><label for=\"username\">Username:</label></td>";
$page_content .= "<td><input type=\"text\" name=\"username\"";

if(isset($_SESSION['username'])) $page_content .= " value=\"" . $_SESSION['username'] . "\"";

$page_content .= "></input></td></tr>\n";
$page_content .= "<tr><td class=\"rightalign\"><label for=\"password\">Password:</label></td>";
$page_content .= "<td><input type=\"password\" name=\"password\"></input></td></tr>\n";
$page_content .= "<tr><td class=\"centered\" colspan=\"2\"><input type=\"submit\" value=\"Login\" /></td></tr>\n";
$page_content .= "</table>\n";
$page_content .= "</form>\n";

// Require template
require TEMPLATE_DIR . "/index.php";
?>